<?php
require_once("config.php");
require_once("Info.php");
require_once("simplexml44-0_4_4/class/IsterXmlSimpleXMLImpl.php");
require_once("ArtistWiki.php");

// Artist bio/wiki section
if(!empty($_GET['artist'])) {
	// read and write a document
	$impl = new IsterXmlSimpleXMLImpl();
	$src = ArtistWiki::getArtistMetadataXML($_GET['artist']);
	if(!strstr($src, "faultCode")) {
		$doc = $impl->load_string($src);
	    $artistMetaMember = $doc->methodResponse->params->param->value->struct->member[3]->value->string->CDATA();
	    $lastfmURL = $doc->methodResponse->params->param->value->struct->member[5]->value->string->CDATA();
	    $profileImg = $doc->methodResponse->params->param->value->struct->member[6]->value->string->CDATA();
	    $tags = $doc->methodResponse->params->param->value->struct->member[7]->value->array->data;
		$artistBio = '<h3>'.ucwords(strtolower($_GET['artist'])).'</h3>';
	    $artistBio .= '<img src="'.$profileImg.'" />';
	    $artistBio .= ArtistWiki::stripBBCode($artistMetaMember);
	    //$artistBio .= '<br/><br/><strong>Tags:</strong> ';
	    //foreach($tags->children() as $tag) {
	    //    Info::dump($tag->value->string->CDATA());
	    //}
	    $artistBio .= '<br/><a href="'.$lastfmURL.'">Last.fm profile</a><br/><br/>';
	    echo $artistBio;
    } else {
        echo "<em>Open bug #1</em>";
    }
} 
?>